﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BoxScore.Objetos;
using BoxScore.Model;
using System.IO;

namespace BoxScore.liga
{
    public partial class Agregar : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void ValidarEnServidor(object source, ServerValidateEventArgs value)
        {
            if (FileUpload1.FileName == String.Empty)
            {
                value.IsValid = true;
                return;
            }
            else
            {
                if (FileUpload1.PostedFile.ContentType.ToLower() == "image/jpeg" || FileUpload1.PostedFile.ContentType.ToLower() == "image/x-png" || FileUpload1.PostedFile.ContentType.ToLower() == "image/gif")
                {
                    value.IsValid = true;
                    return;
                }
            }
            value.IsValid = false;

       }

        protected void Button1_Click(object sender, EventArgs e)
        {
            //guardar liga
            Liga liga = new Liga();
            liga.nombre = txtnombre.Text;
            liga.descripcion = txtdescripcion.Text;

            if (FileUpload1.HasFile)
            {
                string ruta = FileUpload1.FileName;
                string filename = Path.GetFileName(ruta);
                string extension = Path.GetExtension(filename);
                Guid guid = Guid.NewGuid();
                liga.logo = guid.ToString("N") + extension;

                FileUpload1.SaveAs(Server.MapPath("~/liga/images/") + liga.logo);

            }

            BoxScoreBD boxscore = new BoxScoreBD();
            int resultado = boxscore.AgregarLiga(liga);
            Response.Redirect("index.aspx");

            //Response.Write(Request["id"]);
            

        }
    }
}
